
<h1><?php echo $this->page;?> Manage</h1>
<div class="breadcrumb">
        <a href="/admin/index">Home</a>
         :: <a href="/admin/editpage?page=<?php echo $_GET['page'];?>"><?php echo $this->page;?></a>
</div>
<div class="box">
 	<div class="heading">
      <h1><img alt="" src="/images/admin/module.png"> <?php echo $this->page;?></h1>
      <div class="buttons">
	      <a class="button" href="/admin/page"><span>Cancel</span></a>
      </div>
    </div>
    <div class="content">
     <?php 
     if(isset($this->modify) && $this->modify=="true") 
     {
      	if(isset($this->widgets) && $this->widgets!=null) 
      	{?>
	      	<table class="list">
		        <thead>
		          <tr>
		          	<td class="left">No</td>
		            <td class="left">Module Name</td>
		             <td class="left">Position</td>
		            <td class="left">Sort Order</td>
		            <td class="right">Action</td>
		          </tr>
		        </thead>
		        <tbody>
		         	<?php $i=0;
					foreach ($this->widgets as $widget) 
					{
						if($widget["default"]==1) 
						{ $i++;
					?>
		          	<tr>
			           	<td class="left"><?php echo $i;?></td>
			            <td class="left"> <span title="Default Module" style="color: red;">(*) </span><?php  echo $widget["module_title"];?></td>
			            <?php if($widget["module_sort"] >= 0)  {?>
			            <td class="left"><?php  echo $widget["module_type"];?></td>
			            <td class="left"><input type = "text" id = "<?php  echo $widget["module_code"];?>" value="<?php  echo $widget["module_sort"];?>" name = "sort_order" size="50"></input></td>
			            <?php } else {?>
			            <td class="left"></td>
			            <td class="left"><input type = "text" id = "<?php  echo $widget["module_code"];?>" name = "sort_order" value = "" size="50"></input></td>
			            <?php }?>
			            <td class="right">
			           	[ <a href = "javascript:;" onclick="UpdateModule('<?php  echo $widget["module_code"];?>','true')">Update</a> ]
			            </td>
			         </tr>
		          <?php } 
					}?>
		          <?php 
					foreach ($this->widgets as $widget) 
					{
						if($widget["default"]==0) 
						{ $i++;
					?>
		          		<tr>
				          	<td class="left"><?php echo $i;?></td>
				            <td class="left"><?php  echo $widget["module_title"];?></td>
				            <?php if($widget["module_sort"] >= 0)  {?>
				            <td class="left"><?php  echo $widget["module_type"];?></td>
				            <td class="left"><input type = "text" id = "<?php  echo $widget["module_code"];?>" value="<?php  echo $widget["module_sort"];?>" name = "sort_order" size="50"></input></td>
				            <?php } else {?>
				            <td class="left"></td>
				            <td class="left"><input type = "text" id = "<?php  echo $widget["module_code"];?>" name = "sort_order" value = "" size="50"></input></td>
				            <?php }?>
				            <td class="right">
					            <?php if($widget["module_sort"] < 0)  {?>
					            [ <a href = "javascript:;" onclick="InstallModule('<?php  echo $widget["module_code"];?>')">install</a> ]
					            <?php } else {?>
					            [ <a href = "javascript:;" onclick="UpdateModule('<?php  echo $widget["module_code"];?>','false')">Update</a> ]
					            [ <a href = "javascript:;" onclick="UnInstallModule('<?php  echo $widget["module_code"];?>')">Uninstall</a> ]
					            <?php }?>
				           	</td>
				         </tr>
		          <?php } }?>
		       </tbody>
	      </table>
      <?php 
      	} 
      	else 
      	{?>
      		<div style="text-align: center;padding-top:100px;">No Content Module found!</div>
      <?php 
      	} 
     } 
     else 
     {?>
      	<div style="border: 1px solid #DDDDDD; background: #F7F7F7; text-align: center; padding: 15px;">You do not have permission to Modify this page, please refer to your system administrator.</div>
      <?php 
     }?>
    </div>
</div>

<script type="text/javascript">
function InstallModule(module_code)
{ 
	var abc = document.getElementById(String(module_code)).value ;
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{ 
			if(xmlhttp.responseText == "-1")
			{
				alert("There was an error during install");
			}
			else if(xmlhttp.responseText == "-2" )
			{
				alert("You did not enter Sort Module");
			}
			else if(xmlhttp.responseText == "-3")
			{
				alert("Sort Module may only enter >=0");
			}
			else if(xmlhttp.responseText == "-4")
			{
				alert("Sequence number already exists");
			}
			else
			{
				window.location="/admin/editpage?page=<?php echo $_GET['page'];?>";
			}
		}
	};
	var url = "<?php echo $this->installUrl?>?module="+module_code+"&page=<?php echo $_GET['page']?>&sort="+abc;
	xmlhttp.open("GET",url,true);	
	xmlhttp.send();
	return false;
}

function UnInstallModule(module_code)
{
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
		
			if(xmlhttp.responseText == "-1")
			{
				alert("There was an error during Uninstall");
			}
			else
			{			
				window.location="/admin/editpage?page=<?php echo $_GET['page'];?>";
			}
		}	
	};
	var url = "<?php echo $this->unInstallUrl?>?module="+module_code+"&page=<?php echo $_GET['page']?>";
	xmlhttp.open("GET",url,true);	
	xmlhttp.send();
	return false;
}

function UpdateModule(module_code,check)
{
	var abc = document.getElementById(String(module_code)).value ;
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			if(xmlhttp.responseText == "-1")
			{
				alert("There was an error during update");
			}
			else if(xmlhttp.responseText == "-2" )
			{
				alert("You did not enter Sort Module");
			}
			else if(xmlhttp.responseText == "-3")
			{
				alert("Sort Module may only enter >=0");
			}
			else if(xmlhttp.responseText == "-4")
			{
				alert("Sequence number already exists");
			}
			else
			{
				alert("update successful");
			}
		}	
	};
	var url
	if(check=="true")
		url = "<?php echo $this->updateDefaultUrl;?>?module="+module_code+"&page=<?php echo $_GET['page']?>&sort="+abc;
	else
		url = "<?php echo $this->updateContentUrl;?>?module="+module_code+"&page=<?php echo $_GET['page']?>&sort="+abc;
	
	xmlhttp.open("GET",url,true);	
	xmlhttp.send();
	return false;
}

</script>
